#ifndef H_COMMON
#define H_COMMON

#include <glib.h>
#include <xmlsec/xmlsec.h>
#include <openssl/dsa.h>

extern const unsigned char ns_mikolaj[];
extern const unsigned char ns_soap[];
extern const unsigned char ns_dws[];
extern const unsigned char ns_config[];
extern const unsigned char ns_payment[];

struct trustState {
  GHashTable *map;
};

struct config {
  xmlSecKeyPtr root;
  GHashTable *map;
  xmlNodePtr condition;
};

struct signedDocument {
  xmlNodePtr unsignedRoot, signedRoot, authorities, sig;
  xmlSecKeyPtr signingKey;
  xmlSecKeyInfoCtxPtr keyInfo;
  xmlSecDSigCtxPtr signingCtx;
};

struct remuneration {
  double rate;
  char *currency;
  unsigned long quantum;
  xmlNodePtr amount;
};

struct trustState *newTrustState();
void assertSigned(struct trustState *, xmlSecKeyPtr, xmlSecKeyPtr);
void extractKey(xmlSecKeyPtr, xmlNodePtr);
int findPath(struct trustState *, xmlSecKeyPtr, xmlSecKeyPtr);
DSA *getKey(char *);
xmlSecKeyPtr getDNSKey(char *);
GSList *configsForKey(struct trustState *, xmlSecKeyPtr);
void libSetup();
struct signedDocument *validateDocument(char *, xmlNodePtr);
void resolveCertificates(struct signedDocument *, struct trustState *);
xmlSecKeyPtr loadRootKey();
xmlSecDSigCtxPtr processSolicitation(xmlNodePtr);
int chooseSpi();
void yankNameSpaces(xmlNodePtr);
int sendTxn(xmlDocPtr);
xmlDocPtr makeDrawdown(xmlNodePtr, struct remuneration *);
xmlDocPtr makeSoapReq(xmlNodePtr);
int processCompliance(xmlNodePtr, const char *);

xmlNodePtr xuNewDoc(const char *, const char *, const char *);
void xuAddDoc(xmlNodePtr, xmlDocPtr);
xmlNodePtr findOrDie(xmlNodePtr, const unsigned char * const,
		     const unsigned char * const);

int doDebitAuthority(xmlNodePtr, struct remuneration *);
struct remuneration *makeRemuneration(xmlNodePtr);
int doConfigureNetwork(unsigned int, unsigned long);

/* drawdown.c */
char *makeTime(time_t);
void sign(char *, xmlNodePtr);

#endif	/* !H_COMMON */
